<template>
	<view>
		<view class="header">
			<view class="left">{{shopType}}-脚本说明</view>
			<view class="right" @click="jiaoben">
				自定义脚本
			</view>
		</view>
		
		<block v-for="item in jiaobenList" :key="item.id">
			
			<view class="jiaoben" :data-id="item.id" @click="chooseJiaoben(item)">
				<view class="title" style="display: flex; justify-content: space-between;">
					<!-- <block v-for="twoItem in item.message"> -->
						<text>{{can.shopTrade}}拍摄脚本{{item.type==2?'-(自定义)':''}}</text>
						<image src="../../static/images/delete.png" mode="" style="height: 40rpx; width: 40rpx;" @click="deleteJiaoben(item)"></image>
					<!-- </block> -->
				</view>
				<view class="body">
					<block v-for="twoItem,twoIndex in item.message">
						<view>场景{{twoIndex+1}}: {{twoItem.message}}</view>
					</block>
				</view>
				<image v-if="item.id == jiaobenId" src="../../static/images/youxiajiaoxuanzhong.png" class="choose-icon"></image>
			</view>
		</block>
		
		
		<view style="height: 100rpx;width: 100%;">
			
		</view>
		
		<view class="footer-box">
			<view class="cancel" @click="cancel">取消</view>
			<view class="submit" @click="sure">确认</view>
		</view>
	</view>
</template>

<script>
	import Http from "@/utils/http"
	const http = new Http()
	export default {
		data() {
			return {
				jiaobenList:[],
				jiaobenId:null,
				changeList:[],
				can:{},
				shopType:'',
				shopTrade:""
			}
		},
		onShow() {
			this.jiaobenList = [];
			// this.userDiy();
			this.refresh();
		},
		async onLoad(option) {
		  this.can = JSON.parse(option.obj);
		  switch (this.can.cateage) {
		  	case '1':
		  		this.shopType = '账号打标签';
		  		break;
		  	case '2':
		  		this.shopType = '人设破流量';
		  		break;
		  	case '5':
		  		this.shopType = '企业硬广告';
		  		break;
		  	case '6':
		  		this.shopType = '企业做促销';
		  		break;
		  	case '7':
		  		this.shopType = '数字人视频';
		  		break;
		  	case '8':
		  		this.shopType = '视频做爆款';
		  		break;
		  	default:
		  		this.shopType = '';
		  }
		
		},
		methods: {
			deleteJiaoben(item){
				http.get('v1/jiaoben/deleteJiaoBen/'+item.id).then(res=>{
					if(res.data.data == 1){
						this.refresh();
					}
				})
			},
			async refresh(){
				this.jiaobenList = [];
				let res = await http.post("v1/jiaoben/cateageAll",this.can)
				if(res.data.data != undefined){
					res.data.data.forEach(item=>{
						if(item.message){
							item.message = JSON.parse(item.message);
							this.jiaobenList.push(item);
						}
						this.jiaobenId = this.jiaobenList[0].id;
						this.changeList = this.jiaobenList[0].message;
						if(this.jiaobenId != null){
							let obj = {
								id:this.jiaobenId,
								changeList:this.changeList
							}
							uni.$emit('jiaoben',obj);
						}
						
					})
				}
			},
			userDiy(){
				http.get('v1/jiaoben/userId').then(res=>{
					if(res.data.data != undefined){
						res.data.data.forEach(item=>{
							if(item.message){
								item.message = JSON.parse(item.message);
								this.jiaobenList.push(item);
							}
						})
					}
				})
			},
			jiaoben(){
				uni.navigateTo({
					url:"/subpkg/mkvideo/diyJB?id="+this.can.cateage,
				})
			},
			cancel(){
				uni.navigateBack({delta:1,});
				uni.$emit('jiaoben',null);
			},
			sure(){
				uni.navigateBack({delta:1,});
				let obj = {
					id:this.jiaobenId,
					changeList:this.changeList
				}
				uni.$emit('jiaoben',obj);
			},
			chooseJiaoben(data){
				this.jiaobenId = data.id;
				this.changeList = data.message;
			},
		}
	}
</script>

<style scoped lang="scss">
	page{
		background: #f1f1f1;
	}
.header{
	margin: 30rpx;
	display: flex;
	justify-content: space-between;
	.left{
		font-size: 32rpx;
		font-weight: 700;
	}
	.right{
		color: red;
		font-size: 32rpx;
	}
}
.jiaoben{
	background: #ffffff;
	margin: 30rpx;
	border-radius: 12rpx;
	padding: 30rpx;
	position: relative;
	.title{
		font-size: 36rpx;
		font-weight: 700;
		padding-bottom: 20rpx;
		
	}
	.body{
		font-size: 30rpx;
		color: #666;
	}
	.choose-icon{
		position: absolute;
		bottom: 0;
		right: 0;
		height: 60rpx;
		width: 60rpx;
	}
}

.footer-box{
	position: fixed;
	width: 100%;
	height: 100rpx;
	z-index: 99;
	bottom: 0;
	right: 0;
	left: 0;
	background: #ffffff;
	display: flex;
	justify-content: space-between;
	align-items: center;
	.cancel{
		margin: 0 30rpx;
		background: #eee;
		flex: 1;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 40rpx;
	}
	.submit{
		margin: 0 30rpx;
		background: #00008B;
		flex: 1;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 40rpx;
		color: #ffffff;
	}
}
</style>
